
// 
use wasm_bindgen::prelude::*;
use wasm_bindgen_futures::JsFuture;   
use js_sys::Uint8Array; 

pub async fn fetch_url_binary(url: String) -> Result<Uint8Array, JsValue> 
{ 
    let window = web_sys::window().unwrap(); // Browser window 
    let promise = JsFuture::from(window.fetch_with_str(&url)); // File fetch promise 
    let result = promise.await?; // Await fulfillment of fetch 
    let response: web_sys::Response = result.dyn_into().unwrap(); // Type casting 
    let image_data = JsFuture::from(response.array_buffer()?).await?; // Get text
    Ok(Uint8Array::new(&image_data))
}
